/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Component;

import GameObject.ImageObject;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

/**
 *
 * @author Huy
 */
public abstract class MyControlItem {

	protected String toolTipText;
	protected MouseAdapter mouseHandler;
	protected KeyAdapter keyHandler;
	protected ImageObject sprite;
	protected boolean isForcus = false;
	protected boolean isMousePressed = false;
	protected boolean isEnable = true;
	protected boolean isVisible = true;
	protected Color foreColor = Color.BLACK;
	protected Color disableColor = Color.GRAY;

	public String getToolTipText() {
		return toolTipText;
	}

	public void setToolTipText(String toolTipText) {
		this.toolTipText = toolTipText;
	}

	
	public void setDisableColor(Color disableColor) {
		this.disableColor = disableColor;
	}

	public void setForeColor(Color foreColor) {
		this.foreColor = foreColor;
	}

	public ImageObject getSprite() {
		return sprite;
	}

	public void setImage(BufferedImage img) {
		sprite.setImage(img);
	}

	public int getX() {
		return sprite.getX();
	}

	public int getY() {
		return sprite.getY();
	}

	public void setMouseAdapter(MouseAdapter mouse) {
		mouseHandler = mouse;
	}

	public void setKeyAdapter(KeyAdapter key) {
		keyHandler = key;
	}

	public boolean isForcus() {
		return isForcus;
	}

	public void setForcus() {
		isForcus = true;
	}

	public void lostForcus() {
		isForcus = false;
	}

	public void setScaleX(float s) {
		sprite.setScaleX(s);
	}
	public void setScaleY(float s) {
		sprite.setScaleY(s);
	}

	public boolean isEnable() {
		return isEnable;
	}

	public void setEnable(boolean isEnable) {
		this.isEnable = isEnable;
	}

	public boolean isVisible() {
		return isVisible;
	}

	public void setVisible(boolean isVisible) {
		this.isVisible = isVisible;
	}

	public void draw(Graphics2D g) {
		if (!isVisible) {
			return;
		}
		sprite.draw(g);
		if (isForcus) {
			//	g.draw(sprite.getBound());
		}
	}

	public void move(int dx, int dy) {
		sprite.move(dx, dy);
	}

	public void inorge() {
		isMousePressed = false;
	}

	public boolean keyPressed(KeyEvent e) {
		if (isForcus && isVisible && isEnable) {
			if (keyHandler != null) {
				keyHandler.keyPressed(e);
			}
			return true;
		}
		return false;
	}

	public boolean keyReleased(KeyEvent e) {
		if (isForcus && isVisible && isEnable) {
			if (keyHandler != null) {
				keyHandler.keyReleased(e);
			}
			return true;
		}
		return false;

	}

	public boolean mouseDragged(MouseEvent e) {
		if (isEnable && isVisible && ImageObject.isIn(e.getPoint(), sprite.getBound())) {
			return false;
		}
		if (mouseHandler != null) {
			mouseHandler.mouseDragged(e);
		}
		return true;
	}

	public boolean mouseMoved(MouseEvent e) {
		if (!(e == null) && isEnable && isVisible && ImageObject.isIn(e.getPoint(), sprite.getBound())) {
			isMousePressed = false;
			if (mouseHandler != null) {
				mouseHandler.mouseMoved(e);
			}
			return true;
		}
		return false;
	}

	public boolean mousePressed(MouseEvent e) {
		if (isEnable && isVisible && ImageObject.isIn(e.getPoint(), sprite.getBound())) {
			isMousePressed = true;
			if (mouseHandler != null) {
				mouseHandler.mousePressed(e);
			}
			return true;
		}
		return false;
	}

	public boolean mouseReleased(MouseEvent e) {
		if (!(e == null) && isEnable && isVisible && isMousePressed && ImageObject.isIn(e.getPoint(), sprite.getBound())) {

			isForcus = true;
			isMousePressed = false;
			if (mouseHandler != null) {
				mouseHandler.mouseReleased(e);
			}
			return true;
		}
		isForcus = false;
		return false;
	}
}
